const state = {
  uuid: '',
}
const mutations = {
  GETNOTEINFO(state, uuid) {
    //存储uuid
    state.uuid = uuid
  }
}
const actions = {
  //验证码
  async getNoteInfo({commit}, params) {
    let param = {phone: params}
    let result = await uni.$http.post('/im/yunxin/getSmsCode', param)
    console.log("验证码", result)
    if (result.data.code == 200) {
      console.log('uuid:' + result.data.data.uuid)
      commit('GETNOTEINFO', result.data.data.uuid)
      return "ok";
    } else {
      return Promise.reject(new Error(result.data.msg));
    }
  },

  //登录短信
  async toLoginCode({commit}, params) {
    console.log('短信登录参数',params)
    let result = await uni.$http.post('/auth/loginByUserPhone', params)
    console.log("短信登录",result)
    if (result.data.code == 200) {
      uni.setStorage({
        key: "token",
        data: result.data.data,
        success: function() {
          console.log("存储成功")
        }
      })
      return 'ok'
    } else {
      return Promise.reject(new Error(result.data.msg));
    }
  },
  //注册接口
  async register({commit}, params) {
    console.log('注册参数',params)
    let result = await uni.$http.post('/auth/loginByUserPhone', params)
    console.log("注册",result)
    if (result.data.code == 200) {
      return 'ok'
    } else {
      return Promise.reject(new Error(result.data.msg));
    }
  },

  //登录密码
  async login({commit}, params) {
    console.log('登录密码参数',params)
    let result = await uni.$http.post('/auth/login', params)
    console.log('登录密码',result)
    if (result.data.code == 200) {
      uni.setStorage({
        key: "token",
        data: result.data.data,
        success: function() {
          console.log("存储成功")
        }
      })
      return 'ok'
    } else {
      return Promise.reject(new Error(result.data.msg));
    }
  },
 
  //修改密码
  async modifyPassWrod({commit}, params) {
    console.log('修改密码参数',params)
    let result = await uni.$http.put('/auth/modifyPassWrod', params)
    console.log('修改密码',result)
    if (result.data.code == 200) {
      return 'ok'
    } else {
      return Promise.reject(new Error(result.data.msg));
    }
  },
  //个人与企业切换
  async userChange({commit}) {
    let result = await uni.$http.post('/auth/change')
    console.log("个人与企业切换",result)
    if (result.data.code == 200) {
      uni.setStorage({
        key: "token",
        data: result.data.data,
        success: function() {
          console.log("存储成功")
        }
      })
      return 'ok'
    } else {
      return Promise.reject(new Error(result.data.msg));
    }
  }
  

}


//计算属性:在项目在中,为简化数据而生
const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
